<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Array from</title>
</head>
<body>
  <script>
    const m = new Map().set(1, 2)
                       .set(3, 4);
    const s = new Set().add(1)
                       .add(2)
                       .add(3)
                       .add(4);
    console.log(Array.from(m));
    console.log(Array.from(s));

    const iter = {
      *[Symbol.iterator]() {
        yield 1;
        yield 2;
        yield 3;
        yield 4;
      }
    };
    console.log(Array.from(iter));

    function getArgsArray() {
      return Array.from(arguments);
    }

    console.log(getArgsArray(1, 2, 3, 4));
    const a1 = [1, 2, 3, 4];
    const a2 = Array.from(a1, x => x**2);
    const a3 = Array.from(a1, function(x) {
      return x**this.exponent;
    }, { exponent: 2 });
    console.log(a2);
    console.log(a3);
  </script>
</body>
</html>